/**
 * Course			:	ISYS2119 - BIS Development 2
 * Assignment		:	03
 * Date due			:	31/08/2012
 * Program 			:	Saigon Bike Rental Catalogue System
 * 
 * Programmer		:	Vuu Ngoc My Linh - s3342015, Tran Thi Van Anh - s3342025
 * 
 * Attributions		:	Lecture slides, Blackboard, Tutorials, Websites (not in reference list document)
 * ====================================================================
 * Show the About form - information about programmers						
 */

package rmit.ISYS2119.assign03;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JOptionPane;
import javax.swing.JButton;

import java.awt.Color;

import java.awt.FlowLayout;
import java.awt.Font;

import java.awt.GridLayout;
import java.awt.Container;
import java.awt.BorderLayout;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;

public class FormAbout extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// Static Constants
	public final static String FORM_TITLE = "Saigon Bike Rental Catalogue System - About";

	// Constants
	// =========

	private final int X_LOC = 200;
	private final int Y_LOC = 200;
	private final int WIDTH = 500;
	private final int HEIGHT = 250;

	private final String BACK_BUTTON_TEXT = "Back to Main Form";

	private JTextArea aboutTextArea;
	private JScrollPane scrollPanel;
	private JButton backButton;

	public ArrayList<Bike> bikeList;

	public static void main(String[] args) {

		// Assign bike array list
		ArrayList<Bike> bikeList = new ArrayList<Bike>();

		// Create GUI
		FormAbout form = new FormAbout(bikeList);
		form.setVisible(true);

	}

	public FormAbout(ArrayList<Bike> bikeList) {

		this.bikeList = bikeList;

		// Set form property
		// =================
		setTitle(FORM_TITLE);
		setSize(WIDTH, HEIGHT);
		setLocation(X_LOC, Y_LOC);

		// Create and set components
		// =========================

		// Create panels to hold components
		JPanel northPanel = new JPanel();
		JPanel southPanel = new JPanel(
				new FlowLayout(FlowLayout.CENTER, 10, 20));
		JPanel centerPanel = new JPanel();
		JPanel westPanel = new JPanel();
		JPanel eastPanel = new JPanel();

		// Create the north panel
		// ======================

		// Create the header
		JLabel formHeader = new JLabel();
		Font font = new Font("Arial", Font.BOLD, 15);
		formHeader.setText("About");
		formHeader.setFont(font);
		formHeader.setForeground(Color.BLUE);
		northPanel.add(formHeader, BorderLayout.CENTER);

		// Create the south panel
		// ======================

		// Create panels to hold components
		
		JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 10,
				20));
		aboutTextArea = new JTextArea();
		aboutTextArea.setEditable(false);

		// Set layout of this panel
		southPanel.setLayout(new BorderLayout());

		// Create the buttons
		backButton = new JButton(BACK_BUTTON_TEXT);
		buttonPanel.add(backButton);

		// Add the buttonPanel to this panel.
		southPanel.add(buttonPanel, BorderLayout.NORTH);

		// Create the center panel
		// =======================

		// Set the layout of the panels
		GridLayout centerPanelLayout = new GridLayout(1, 1, 5, 5);

		// Create components and add to panels
		// ========================================
		centerPanel.setLayout(centerPanelLayout);
		aboutTextArea = new JTextArea();
		aboutTextArea
				.setText("	ISYS2119 - Business Information Development 2"
						+ "\n"
						+ "	=================================="
						+ "\n"
						+ "  Assignment 02 - Saigon Bike Rental"
						+ "\n"
						+ "  Created by: Vuu Ngoc My Linh (s3342015) and Tran Thi Van Anh (s3342025)"
						+ "\n"
						+ "  Attributions: Lecture slides, Blackboard, Tutorials, Websites"
						+ "\n" + "  Date finish: 30/07/2012");

		
		aboutTextArea.setWrapStyleWord(true);
		aboutTextArea.setEditable(false);
	
		centerPanel.add(aboutTextArea);
		scrollPanel = new JScrollPane(aboutTextArea);
		centerPanel.add(scrollPanel);

		// Get the container holding the components of this class
		Container con = getContentPane();

		// Set layout of this class
		con.setLayout(new BorderLayout());

		// Add the fieldsPanel and buttonsPanel to this class.
		con.add(northPanel, BorderLayout.NORTH);
		con.add(southPanel, BorderLayout.SOUTH);
		con.add(centerPanel, BorderLayout.CENTER);
		con.add(westPanel, BorderLayout.WEST);
		con.add(eastPanel, BorderLayout.EAST);

		// Register listeners
		// ==================

		// Register action listeners on buttons
		backButton.addActionListener(this);

		// Exit program when window is closed
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e) {
				System.exit(0);
			}
		});

	}

	public void actionPerformed(ActionEvent ae) {

		try {
			switch (ae.getActionCommand()) {

			// Go back to main form
			case BACK_BUTTON_TEXT:
				ButtonFunctionality.backToMainForm(bikeList);

				// Close this form
				this.dispose();
				break;

			default:
				throw new Exception("Unknown event!");
			}
		} catch (Exception e) {
			JOptionPane.showMessageDialog(this, e.getMessage(), "Error!",
					JOptionPane.ERROR_MESSAGE);
			e.printStackTrace();
		}

	}

}
